﻿@using Smartstore.Core.Checkout.Cart;
@using Smartstore.Core.Catalog.Products;
@using Smartstore.Web.Models.Cart;

@model WishlistModel

@{
    var parentViewData = new ViewDataDictionary(ViewData);
    parentViewData["Parent"] = Model;
}

@foreach (var item in Model.Items)
{
    <div role="listitem" aria-label="@item.ItemSummaryLabel" class="cart-row">
        <div sm-if="Model.DisplayAddToCart && !Model.IsEditable" class="position-absolute">
            <input type="checkbox" name="addtocart" class="form-check-input" value="@item.Id" aria-labelledby="cart-item-link-@item.Id" />
        </div>

        <div class="row">
            @* Image *@
            <div sm-if="Model.ShowProductImages && item.Image != null && item.Image.HasImage()" class="cart-item-img col-3">
                <img sm-model="item.Image" class="img-fluid" attr-alt='(item.Image.Alt.IsEmpty(), item.ProductName)' />
            </div>

            @* Data *@
            <div class="cart-item-data col">
                <partial name="CartItem.Details" model="item" view-data="parentViewData" />

                @* Custom zone *@
                <zone name="wishlistitem_data_after" model="item.Id"></zone>

                @* Actions *@
                <div sm-if="Model.IsEditable" class="cart-item-actions hstack flex-wrap pt-2">
                    <button class="btn btn-secondary btn-to-danger btn-sm btn-icon ajax-action-link"
                            type="button"
                            title="@T("Common.Remove")"
                            data-href='@Url.Action("DeleteCartItem", "ShoppingCart", new { cartItemId = item.Id, isWishlist = true })'
                            data-name="@item.ProductName"
                            data-type="wishlist"
                            data-action="remove"
                            aria-label="@T("Common.Remove")">
                        <i class="far fa-trash-can" aria-hidden="true"></i>
                    </button>

                    <div class="cart-item-qty">
                        @Html.EditorFor(x => item, "QtyInput", new
                        {
                            size = ControlSize.Small,
                            htmlAttributes = new
                            {
                                data_href = Url.Action("UpdateCartItem", "ShoppingCart", new { cartItemId = item.Id, isCartPage = true }),
                                data_sci_item = item.Id,
                                id = $"itemquantity{item.Id}",
                                name = $"itemquantity{item.Id}"
                            }
                        })

                        <span class="field-validation-valid" 
                              data-valmsg-for="itemquantity@(item.Id)" 
                              data-valmsg-replace="true"
                              role="alert"></span>

                        <script>
                            $(function () {
                                // Disable incorrect jquery validation of the step attribute for quantity inputs.
                                setTimeout(function () {
                                    $('#itemquantity@(item.Id)').rules('add', { step: 1 });
                                }, 10);
                            });
                        </script>
                    </div>

                    <button sm-if="Model.DisplayAddToCart && !item.DisableBuyButton" 
                            type="button"
                            class="btn btn-primary btn-sm ajax-action-link"
                            title="@T("ShoppingCart.AddToCart")"
                            data-href="@Url.Action("MoveItemBetweenCartAndWishlist", "ShoppingCart", new { cartItemId = item.Id, cartType = ShoppingCartType.Wishlist, isCartPage = true })"
                            data-name="@item.ProductName"
                            data-type="cart"
                            data-action="addfromcart">
                        <i class="fa fa-cart-arrow-down" aria-hidden="true"></i>
                        <span class="d-none d-md-inline">@T("ShoppingCart.AddToCart")</span>
                    </button>
                </div>
            </div>
        </div>
    </div>

    @if (item.ProductType == ProductType.BundledProduct)
    {
        <partial name="CartItem.BundleItems" model="item.ChildItems" view-data="parentViewData" />
    }
}